from selenium.webdriver.common.by import By

from common.Utils import ForumDriver

class HomepageTest:
    url=""
    driver=""
    def __init__(self):
        self.url="http://127.0.0.1:9580/index.html"
        self.driver=ForumDriver.driver
        self.driver.get(self.url)

    #测试首页元素是否完整，对应可以点击的功能如何
    def HomepageEleTest(self):
        #搜索项
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input")
        #论坛图标
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > h1 > a > img")
        #夜间白天模式
        ForumDriver.getScreenShot()
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-dark > svg").click()
        ForumDriver.getScreenShot()
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-light > svg").click()
        ForumDriver.getScreenShot()

        #点击帖子标题是否可以跳转到帖子详情页
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").click()
        excepted_url="http://127.0.0.1:9580/index.html?theme=light"
        current_url=self.driver.current_url
        if current_url==excepted_url:
            print("点击帖子标题可以跳转到帖子详情页！")
        else:
            print("点击帖子标题不可以跳转到帖子详情页！")
        self.driver.back()

        #发表帖子的网友昵称
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col > ul > li:nth-child(1)")
        #帖子发表时间
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col > ul > li:nth-child(2)")
        #帖子浏览量
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(1)")
        #帖子点赞数
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(2)")
        #帖子评论数
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul > li:nth-child(3)")
        #帖子网友头像
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col-auto > span")
        #消息提示选项
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a > svg")
        #用户信息有无
        #头像
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col-auto > span")
        #昵称
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_nickname")
        #用户身份
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_name_sub")
        #点击用户头像或昵称是否有提示选项
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col-auto > span").click()
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.dropdown > div")
        #截图
        ForumDriver.getScreenShot()

    #消息提醒
    def HomepageMessageAlert(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a > svg").click()
        #是否有[已回复]标签，[未读]标签，[已读]标签?打印出来
        print(self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div:nth-child(1) > div > div.col.text-truncate > a > span.index_message_item_statue").text)
        print(self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div:nth-child(2) > div > div.col.text-truncate > a > span.index_message_item_statue").text)
        print(self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div:nth-child(6) > div > div.col.text-truncate > a > span.index_message_item_statue").text)
        #是否有消息预览
        self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div:nth-child(1) > div > div.col.text-truncate > div")

        ForumDriver.getScreenShot()

        #点击消息标题，不输入文本，是否不可以回复消息
        # 点击标题
        # self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div:nth-child(1) > div > div.col.text-truncate > a > span:nth-child(2)").click()
        # # 到了消息详情页，点击“回复”
        # self.driver.find_element(By.CSS_SELECTOR, "#btn_index_message_reply").click()
        # # 找到回复框，清空
        # self.driver.find_element(By.CSS_SELECTOR, "#index_message_reply_receive_content").clear()
        # # 点击“发送”
        # self.driver.find_element(By.CSS_SELECTOR, "#btn_index_send_message_reply").click()
        # # 提示要输入发送的内容
        # print(self.driver.find_element(By.CSS_SELECTOR, "#index_message_reply_modal").text)










